<?php		

class CommonAdmin extends AdminBase{


	/**
	 * 构造函数，初始化插件
	 */
	public function __construct() {
		parent::__construct();
		
		//将标准头加进来，在析构函数中加了标准尾。对于风格的变化，只需要调整标准头标准尾
		if(!in_array(strtolower(N_ACTION),array('vcode','wapvcode','wapcalendar','encodepng'))){
			n_mod('skin')->header();
		}

	}

	public function fixHtml(){
		$param = $this->param("content:char");
		//$rs['src'] = $param['content'];
		$rs['fix'] = n_api("content")->fixHtml($_POST['content']);
		// print_r($rs);
		$this->_html("fixHtml",$rs);
			
	}

	public function index(){
		echo 'error';
	}
	public function vcode(){
		$vcode = new Vcode();
		$vcode->outImg();
	}
	public function wapVcode(){
		$vcode = new Vcode();
		$vcode->outImg();
	}
	public function Calendar(){
		$this->wapCalendar();
	}
	public function wapCalendar(){
		
		$param = $this->param("calendarDate:char:ignore,path:char:ignore");
		
		if(empty($param['calendarDate']) || !preg_match("/^\\d{4}-\\d{1,2}-\\d{1,2}$/",$param['calendarDate'])){
			$param['calendarDate'] = date("Y-m-d");
		}
		
		list($rs['year'],$rs['month'],$rs['day'])=explode('-',$param['calendarDate']);
		
		
		if(empty($_SERVER['HTTP_REFERER'])){
			throw new PException("找不到入口页");
		}
		if(empty($param['path'])){
			$param['path'] = $_SERVER['HTTP_REFERER'];
		}
		//print_r($param);
		$urlPath = parse_url($param['path']);
		if(!empty($urlPath['path'])){
			$rs['path'] = $urlPath['path'];
		}
		//print_r($urlPath);
		if(!empty($urlPath['query'])){
			parse_str($urlPath['query'],$query);
			
			if(isset($query['cdate'])){
				unset($query['cdate']);
			}
			if(!empty($query)){
				$rs['path'] .= '?'.http_build_query($query);
			}
		}else{
				$rs['path'] .= '?_r=1';
		}
		//print_r($urlPath);
		//print_r($rs);
		$this->_html('wapCalendar',$rs);
	}

	public function encodePng(){
		$param = $this->param("data:char");
		$qr = new QRcode();
		$qr->png($param['data']);
		exit;
	}

		
	public function __destruct(){
		
		//加入标准尾。
		if(!in_array(strtolower(N_ACTION),array('vcode','wapvcode','wapcalendar','encodepng'))){
			n_mod('skin')->footer();		
		}
	}
}

